<template>
  <div o-Container>
    <o-list v-bind:source="list.company"
            v-bind="{created:create,modified:modify,searched:search}"/>
    <o-dialog v-bind:source="panel" v-bind="{opened:load,closed:load}">
      <template slot="content">
        <o-item v-bind:source="item.company" v-bind="{saved:save,backed:back}"></o-item>
      </template>
    </o-dialog>
  </div>
</template>

<script>
  export default {
    name: "mms_platform_company_list", /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */
    data() {
      return {
        octopus: this.$parent.octopus,
        list: {
          company: {
            data: {
              id: 31, // 菜单表的八爪鱼ID
              cellData: [
                {name: "SourceTypeID", width: 50, searchKey: "LIKE"},//
                // {name: "ParentID", searchKey: "LIKE"},//公司名称
                {name: "Name", width: 120, searchKey: "LIKE"},//公司名称
                {name: "FullName", width: 200, searchKey: "LIKE"},//公司全称
                {name: "UniqueCode", width: 270, searchKey: "LIKE"},//公司名称
                {name: "Contacts", width: 90},//联系人
                {name: "ContactsMobile", width: 100},//联系电话
                {name: "ContactsMail", width: 150},//邮箱
                {name: "CreateTime", width: 160, searchKey: "BETWEEN"},//创建时间
                {name: "ExpiredTime", width: 160},//开业时间
              ],
              paramData: {}
            }
          },
        },
        item: {
          company: {
            // 以下参数默认由组件内部创建，但是如果有需要，开发人员可在这里提前设置，组件将按照您的预期渲染。
            data: {
              id: 31,
              value: "",
              cellData: [
                {name: "ParentID"},//名称
                {name: "FullName"},//全称
                {name: "Name"},//名称
                {name: "SourceTypeID"},//
                {name: "Contacts"},//联系人
                {name: "ContactsMobile"},//联系电话
                {name: "ContactsMail"},//邮箱
                {name: "UniqueCode"},//营业执照编号
                {name: "LicenseNumber"},//营业执照编号
                {name: "CreateTime"},//创建时间
                {name: "ExpiredTime"},//开业时间
                {name: "Address"},//地址
                {name: "Introduction"},//介绍
                {name: "Logo"},//标致
              ]
            },
          },
        },
        panel: {
          visible: false,
        },
      }
    },
    created() {
      this.init()
    },
    methods: {
      init() {
        const cellData = this.list.company.data.cellData;
        // 遍历 cellData，找到符合条件的元素，并添加键值对
        cellData.forEach(item => {
          if (item.name === "CompanyID") {
            // 添加 filterKey 和 filterValue
            item.filterKey = '=';
            item.filterValue = this.octopus.passport.authorization.company == 1 ? '' : this.octopus.passport.authorization.company;
          }
        });
      },
      create: function () {//弹出创建页面
        this.item.company.data.value = null;
        this.item.company.control.load();
        this.panel.visible = true;
      },
      output: function (data) {
        // 导出以后，回调这里给客户端操作。
        // 核心思想是cellData包含search数据（不管有没有），回传以后发送export指令，后台api会直接返回导出的数据提供下载。
        alert("export: get cell data is " + JSON.stringify(data));
      },
      search: function (cell) {
      },
      modify: function (row) {//修改页面
        this.item.company.data.value = row.ID;
        this.item.company.control.load();
        this.panel.visible = true;
      },
      view: function (row) {
        alert("view key: " + JSON.stringify(row));
      },
      del: function (row) {
        alert("del key: " + JSON.stringify(row));
      },
      save: function (data) {// 保存
        this.octopus.tips.success(data);
        // 刷新list
        this.list.company.control.load();
        this.back();
      },
      back: function () {
        this.panel.visible = false;
      },
    },
    props: ["oData"]
  }
</script>
